package fr.cnam.projetSiw.client.structure.pages;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

import fr.cnam.projetSiw.client.core.ClientFactory;
import fr.cnam.projetSiw.client.core.GeolocationManager;
import fr.cnam.projetSiw.client.core.ZicActivity;
import fr.cnam.projetSiw.client.services.LastFmService;
import fr.cnam.projetSiw.client.services.LastFmServiceAsync;
import fr.cnam.projetSiw.shared.MusicEvent;

public class HomeActivity extends ZicActivity implements HomeView.Presenter{

	 private LastFmServiceAsync lastFmService = GWT.create(LastFmService.class);


	public HomeActivity(ClientFactory clientFactory)
	{
		super(clientFactory);
	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus) {
		final HomeView view = clientFactory.getHomeView();	
		view.setPresenter(this);
		GeolocationManager manager = GeolocationManager.getInstance();
		
		lastFmService.getEventsByLatAndLon(manager.getPosition().getCoordinates().getLatitude(), manager.getPosition().getCoordinates().getLongitude(), new AsyncCallback<ArrayList<MusicEvent>>()
		{

			@Override
			public void onFailure(Throwable caught)
			{
				System.out.println(caught.getStackTrace());
				
			}

			public void onSuccess(ArrayList<MusicEvent> result)
			{
				view.setData(result);

			}
		});
		panel.setWidget(view.asWidget());
		 
	}


	

}
